package cn.amaake.magicplugin.rpc.service;

import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.RpcException;

public class MyExporterListener implements ExporterListener {

    private MagicApiGenericService magicApiGenericService;

    public MyExporterListener(MagicApiGenericService magicApiGenericService){
        this.magicApiGenericService = magicApiGenericService;
    }

    @Override
    public void exported(Exporter<?> exporter) throws RpcException {
        // 服务暴露成功
        magicApiGenericService.setExported(true);
        System.out.println("Service " + exporter.getInvoker().getInterface().getName() + " exported.");

    }

    @Override
    public void unexported(Exporter<?> exporter) {
        // 服务取消暴露
        magicApiGenericService.setExported(false);
        System.out.println("Service " + exporter.getInvoker().getInterface().getName() + " unexported.");
    }
}
